const resultEnum = require('../utils/resultEnum').ResultEnum;
const Mock = new(require('../utils/mock')).Mocks();

/* 查询用户信息 */
function selectUserInfo(ctx, next) {
  try {
    const params = {
      ...ctx.query
    };

    /* 模拟查询数据库，处理后返回 */
    /* 返回对象 */
    if (ctx.request.header.authorization === 'Bearer 11') {
      ctx.error(resultEnum.GET_ACCESS_TOKEN_Expired.code, resultEnum.GET_ACCESS_TOKEN_Expired.msg)
    } else {
      ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getUserList())
    }
  } catch (error) {
    ctx.error(resultEnum.GET_ERROR.code, resultEnum.GET_ERROR.msg)
  }
}

/* 查询用户信息（注册用户） */
function selectUserListInfo(ctx, next) {
  try {
    const params = {
      ...ctx.query
    };

    // console.log(ctx.state);
    /* 模拟查询数据库，处理后返回 */
    /* 返回对象 */
    //  console.log(ctx.response);
    console.log('start--->2');
    ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getUserList1())
  } catch (error) {
    ctx.error(resultEnum.GET_ERROR.code, resultEnum.GET_ERROR.msg)
  }
}

/* 查询用户信息 */
function selectUser(ctx, next) {
  const params = {
    ...ctx.query
  };
  console.log(params);
  ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getUserById())
}
/* 查询用户信息通过id */
function selectUserInfoById(ctx, next) {
  const params = {
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getUserById())
}

/* 新增用户信息 */
function insertUser(ctx, next) {
  const params = {
    ...ctx.request.body
  };
  console.log(params);
  ctx.success(resultEnum.SAVE_SUCCESS.code, resultEnum.SAVE_SUCCESS.msg)
}
/* 获取token信息 */
function getToken(ctx, next) {
  const params = {
    ...ctx.request.body
  };
  console.log(params);
  ctx.success(resultEnum.GET_TOKEN_SUCCESS.code, resultEnum.GET_TOKEN_SUCCESS.msg, Mock.getToken())
}
/* 刷新refreshToken信息 */
function getRefreshToken(ctx, next) {
  const params = {
    ...ctx.request.body
  };
  console.log(params);
  ctx.success(resultEnum.GET_TOKEN_SUCCESS.code, resultEnum.GET_TOKEN_SUCCESS.msg, Mock.getToken())
}

/* 更新用户信息 */
function updateUser(ctx, next) {
  const params = {
    ...ctx.request.body,
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.UPDATE_SUCCESS.code, resultEnum.UPDATE_SUCCESS.msg)
}

/* 删除用户信息 */
function deleteUser(ctx, next) {
  const params = {
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.DELETE_SUCCESS.code, resultEnum.DELETE_SUCCESS.msg)
}

module.exports = {
  selectUserInfo,
  selectUserListInfo,
  selectUser,
  selectUserInfoById,
  insertUser,
  getToken,
  getRefreshToken,
  updateUser,
  deleteUser
}